home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / sendmail.cf / bin / restartsendmail < prev    next >
Encoding:
Text File  |  1987-05-14  |  2.3 KB  |  105 lines

  1. #!/bin/csh -f
  2.  
  3. set TRUE = 1
  4. set FALSE = 0
  5.  
  6. set debug = $FALSE
  7. set freeze = $FALSE
  8. set verbse = $FALSE
  9.  
  10. while ($#argv >= 1)
  11.     set flags = `expr $argv[1] : '-\(.*\)'`
  12.     if ("$flags" == "") \
  13.     break
  14.     while ("$flags" != "")
  15.     set flag = `expr $flags : '\(.\)'`
  16.     set flags = `expr $flags : '.\(.*\)'`
  17.     switch ($flag)
  18.         case "d":
  19.         set debug = $TRUE
  20.         breaksw
  21.         case "v":
  22.         set verbse = $TRUE
  23.         breaksw
  24.         case "z":
  25.         set freeze = $TRUE
  26.         breaksw
  27.         default:
  28.         echo "unknown flag -$flag"
  29.         exit -1
  30.     endsw
  31.     end
  32.     shift
  33. end
  34.  
  35. if ($freeze) then
  36.     if ($debug || $verbse) \
  37.     echo "freezing configuration file"
  38.     if (! $debug) then
  39.     /usr/lib/sendmail -bz
  40.     endif
  41. endif
  42.  
  43. # okay, try and find the sendmail daemon
  44. #  heuristics: find all processes with the string "/usr/lib/sendmail "
  45. #     or "(sendmail)".  Of these, find the process with the string "bd"
  46. #     and the lowest pid, or (if no process with "bd") just the process
  47. #     with the lowest pid.
  48.  
  49. set TMPFILE = /tmp/restart.$$
  50.  
  51. ps ax | \
  52.     egrep '[0-9]+:[0-9]+[ ]+/usr/lib/sendmail -bd\
  53. [0-9]+:[0-9]+[ ]+\(sendmail\)' | grep -v grep > $TMPFILE
  54.  
  55. set wordcount = `wc -l $TMPFILE`
  56. set lines = $wordcount[1]
  57.  
  58. set i = 1
  59. set pid = 0
  60. set daemonfound = $FALSE
  61.  
  62. while ( $i <= $lines )
  63.     set line = `tail +$i $TMPFILE | head -1`
  64.     @ i++
  65.     if ($debug || $verbse) \
  66.     echo "sendmail process: $line"
  67.     set daemonline = `echo "$line" | grep -e -bd`
  68.     if ("$daemonline" != "") then
  69.     if ($debug || $verbse) \
  70.         echo "found daemon sendmail: $daemonline"
  71.     if ((! $daemonfound) || $pid == 0) then
  72.         if ($debug || $verbse) \
  73.         echo "initializing pid to daemon pid $daemonline[1]"
  74.         set pid = $daemonline[1]
  75.         set daemonfound = $TRUE
  76.     else if ($daemonline[1] < $pid)
  77.         if ($debug || $verbse) \
  78.         echo "replacing pid $pid with lower daemon pid $daemonline[1]"
  79.         set pid = $daemonline[1]
  80.     endif
  81.     else if (! $daemonfound) then
  82.     if ($pid == 0 || $line[1] < $pid) then
  83.         if ($debug || $verbse) \
  84.         echo "replacing pid $pid with sendmail pid $line[1]"
  85.         set pid = $line[1]
  86.     endif
  87.     endif
  88. end
  89.  
  90. rm -f $TMPFILE
  91.  
  92. if ($pid != 0) then
  93.     if ($debug || $verbse) \
  94.     echo "killing sendmail daemon at pid $pid, restarting"
  95.     if (! $debug) then
  96.     kill -9 $pid
  97.     /usr/lib/sendmail -bd -q1h
  98.     endif
  99. else
  100.     echo "couldn't find sendmail to kill, restarting"
  101.     if (! $debug) then
  102.     /usr/lib/sendmail -bd -q1h
  103.     endif
  104. endif
  105.